package com.example.shaoying.yuejian.activity;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.shaoying.yuejian.R;
import com.example.shaoying.yuejian.adapter.UserDingdanAdapter;
import com.example.shaoying.yuejian.adapter.UserGuanZhuAdapter;
import com.example.shaoying.yuejian.javabean.DingDan;
import com.example.shaoying.yuejian.javabean.UserGuanzhu;
import com.example.shaoying.yuejian.model.UserModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class UserDingDanActivity extends Activity {

    private RecyclerView recyclerView;
    private UserDingdanAdapter adapter;
    private String userId;
    private String sessionid;
    private SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dingdan);
        recyclerView= (RecyclerView) findViewById(R.id.user_guanzhu_recyclerview);
        sp = getSharedPreferences("login_uid", Context.MODE_PRIVATE);
        sessionid=sp.getString("sessionId","");
        userId=sp.getString("userId","");

        UserModel model=new UserModel();
        Call<List<DingDan>> call=model.getDingDan(userId,"0","1",sessionid);
        call.enqueue(new Callback<List<DingDan>>() {
            @Override
            public void onResponse(Call<List<DingDan>> call, Response<List<DingDan>> response) {
                List<DingDan> list=response.body();
                adapter=new UserDingdanAdapter(UserDingDanActivity.this,list);
                LinearLayoutManager linearLayoutManager=new LinearLayoutManager(UserDingDanActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setAdapter(adapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFailure(Call<List<DingDan>> call, Throwable t) {
                Toast.makeText(UserDingDanActivity.this,"获取列表失败",Toast.LENGTH_SHORT).show();
            }
        });
    }
}
